// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 

package com.sec.android.app.calculator;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Typeface;
import android.os.Handler;
import android.os.Message;
import android.text.Editable;
import android.text.SpannableStringBuilder;
import android.text.style.ForegroundColorSpan;
import android.text.style.ScaleXSpan;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.EditText;
import java.math.BigDecimal;
import java.text.NumberFormat;
import java.util.Locale;

// Referenced classes of package com.sec.android.app.calculator:
//            SyntaxException, Cmyfunc, CExpression, History

public class EventHandler
{

    EventHandler(Context context, EditText edittext, EditText edittext1, History history)
    {
        exception = new SyntaxException();
        mIsError = false;
        mCursorState = false;
        isSelecting = false;
        isLongClick = false;
        mEnterEnd = false;
        mPaste = false;
        delst = false;
        frontText = "";
        errorCursor = 0;
        String as[] = new String[8];
        as[0] = "sin(";
        as[1] = "cos(";
        as[2] = "tan(";
        as[3] = "ln(";
        as[4] = "abs(";
        as[5] = "log(";
        as[6] = "^(";
        as[7] = "\u221A(";
        checkChar = as;
        handler = new Handler() {

            public void handleMessage(Message message)
            {
                if(message.what == 0 && delst)
                {
                    onBackspace();
                    handler.sendEmptyMessage(0);
                }
            }

            final EventHandler this$0;

            
            {
                this$0 = EventHandler.this;
                super();
            }
        }
;
        sb = new StringBuilder();
        mContext = context;
        mDisplay = edittext;
        mHistoryScreen = edittext1;
        mHistory = history;
        mType = Typeface.createFromAsset(mContext.getAssets(), "fonts/GS45_EU_TouchWiz.ttf");
    }

    public static int checkCharCount(StringBuilder stringbuilder, String s)
    {
        int i = 0;
        int j = 0;
        int l;
        if(stringbuilder.length() == 0)
        {
            l = 0;
        } else
        {
            do
            {
                int k = stringbuilder.indexOf(s, j);
                if(k <= 0)
                    break;
                i++;
                j = k + s.length();
            } while(true);
            l = i;
        }
        return l;
    }

    private void clearSB()
    {
        int i = sb.length();
        if(i != 0)
            sb.delete(0, i);
    }

    public static String doubleToString(double d)
    {
        String s = Double.toString(Math.abs(d));
        StringBuffer stringbuffer = new StringBuffer(s);
        int i = s.lastIndexOf('E');
        int j;
        int k;
        int l;
        if(i != -1)
            j = Integer.parseInt(s.substring(i + 1));
        else
            j = 0;
        if(i != -1)
            stringbuffer.setLength(i);
        k = stringbuffer.length();
        for(l = 0; l < k && stringbuffer.charAt(l) != '.'; l++);
        int i1 = j + l;
        if(l < k)
        {
            stringbuffer.deleteCharAt(l);
            k--;
        }
        int j1;
        if(i1 < 16 && k >= 17 || i1 < -9)
            j1 = k - 1;
        else
            j1 = 10 + i1;
        int k1;
        if(j1 < k)
        {
            int l1;
            int i2;
            int j2;
            int k2;
            int l2;
            int i3;
            int j3;
            int k3;
            int l3;
            if(stringbuffer.charAt(j1) >= '5')
            {
                int i4;
                for(i4 = j1 - 1; i4 >= 0 && stringbuffer.charAt(i4) == '9'; i4--)
                    stringbuffer.setCharAt(i4, '0');

                if(i4 >= 0)
                {
                    stringbuffer.setCharAt(i4, 1 + stringbuffer.charAt(i4));
                    k1 = i1;
                    l3 = j1;
                } else
                {
                    stringbuffer.insert(0, '1');
                    int j4 = j1 + 1;
                    k1 = i1 + 1;
                    l3 = j4;
                }
            } else
            {
                k1 = i1;
                l3 = j1;
            }
            stringbuffer.setLength(l3);
        } else
        {
            k1 = i1;
            int _tmp = j1;
        }
        if(k1 < -5 || k1 > 15)
        {
            if(stringbuffer.length() > 0)
            {
                stringbuffer.insert(1, '.');
                l1 = k1 - 1;
            } else
            {
                l1 = k1;
            }
        } else
        {
            for(j3 = k; j3 < k1; j3++)
                stringbuffer.append('0');

            for(k3 = k1; k3 <= 0; k3++)
                stringbuffer.insert(0, '0');

            if(k1 <= 0)
                k1 = 1;
            stringbuffer.insert(k1, '.');
            l1 = 0;
        }
        i2 = stringbuffer.length();
        for(j2 = 0; j2 < i2 && stringbuffer.charAt(j2) != '.'; j2++);
        k2 = i2 - j2 - 1;
        if(k2 > 10)
        {
            k2 -= 10;
            for(i3 = 0; i3 < k2; i3++)
                stringbuffer.setCharAt(1 + (i3 + (j2 + 10)), '0');

        }
        int _tmp1 = k2;
        for(l2 = i2 - 1; l2 >= 0 && stringbuffer.charAt(l2) == '0'; l2--)
            stringbuffer.deleteCharAt(l2);

        if(l2 >= 0 && stringbuffer.charAt(l2) == '.')
            stringbuffer.deleteCharAt(l2);
        if(l1 != 0)
            stringbuffer.append('E').append(l1);
        if(d < 0.0D)
            stringbuffer.insert(0, '-');
        return stringbuffer.toString();
    }

    public static String doubleToString(double d, int i)
    {
        return sizeTruncate(doubleToString(d), i);
    }

    private void insertComma(String s, int i, int j)
    {
        insertComma(new StringBuilder(s), i, j);
    }

    private void insertComma(StringBuilder stringbuilder, int i, int j)
    {
        StringBuilder stringbuilder1;
        StringBuilder stringbuilder2;
        int k;
        int i1;
        int j1;
        int l1;
        stringbuilder1 = getTextBuilder();
        stringbuilder2 = new StringBuilder();
        k = stringbuilder1.length();
        int l = stringbuilder.length();
        i1 = 0;
        j1 = 0;
        int k1;
        char c3;
        if(i - l >= 0)
            k1 = i - l;
        else
            k1 = 0;
        l1 = k1 - 1;
_L6:
        if(l1 < 0) goto _L2; else goto _L1
_L1:
        c3 = stringbuilder1.charAt(l1);
        if(Cmyfunc.isOnlyDigit(c3) || c3 == '.') goto _L4; else goto _L3
_L3:
        i1 = l1 + 1;
        if(k1 != i1) goto _L2; else goto _L5
_L5:
        return;
_L4:
        l1--;
          goto _L6
_L2:
        int i2 = j;
_L7:
        StringBuilder stringbuilder3;
        int j2;
        int k2;
        int l2;
        if(i2 <= k)
            if(i2 == k)
            {
                j1 = k;
            } else
            {
label0:
                {
                    char c2 = stringbuilder1.charAt(i2);
                    if(Cmyfunc.isOnlyDigit(c2) || c2 != '.')
                        break label0;
                    j1 = i2;
                }
            }
        stringbuilder3 = removeSub(stringbuilder1, i1, j1);
        j2 = 0;
        k2 = 0;
        l2 = 0;
_L8:
        if(l2 <= stringbuilder3.length())
        {
            if(l2 != stringbuilder3.length())
                break MISSING_BLOCK_LABEL_260;
            stringbuilder2.append(changeNumFomat(stringbuilder3.substring(j2, l2)));
        }
        if(stringbuilder2.length() != 0)
            mDisplay.getText().replace(i1, j1, changeColor(stringbuilder2));
          goto _L5
        i2++;
          goto _L7
        l2++;
          goto _L8
        char c;
label1:
        {
            c = stringbuilder3.charAt(l2);
            char c1;
            if(l2 < stringbuilder3.length() - 1)
                c1 = stringbuilder3.charAt(l2 + 1);
            else
                c1 = '\0';
            if(Cmyfunc.isOnlyDigit(c) || c == '.')
                break label1;
            if(c == 'E' && (c1 == '-' || Cmyfunc.isOnlyDigit(c1) || c1 == '+') || k2 == 69 && (c == '-' || Cmyfunc.isOnlyDigit(c) || c == '+'))
                break MISSING_BLOCK_LABEL_336;
            stringbuilder2.append(changeNumFomat(stringbuilder3.substring(j2, l2)));
            stringbuilder2.append(c);
            j2 = l2 + 1;
        }
        k2 = c;
        break MISSING_BLOCK_LABEL_336;
    }

    private void reCalculation()
    {
        String s;
        int i;
        StringBuilder stringbuilder;
        s = getText();
        i = s.indexOf("=");
        stringbuilder = new StringBuilder(s.substring(0, i));
        if(s.length() >= i + 1) goto _L2; else goto _L1
_L1:
        Log.v("Calculator : reCalculaton", (new StringBuilder()).append("java.lang.StringIndexOutOfBoundsException").append(s.length()).append(" : ").append(i).toString());
        clearResult();
_L13:
        return;
_L2:
        String s1;
        String s2;
        s1 = s.substring(i + 1).replaceAll(",", "");
        s2 = "";
        String s5;
        s2 = evaluate(stringbuilder, true);
        s2 = doubleToString(Double.parseDouble(s2), 15);
        int j2 = s2.length() - 1;
        if(s2.charAt(j2) != '.')
            break MISSING_BLOCK_LABEL_167;
        int k2 = s2.length() - 1;
        s5 = s2.substring(0, k2);
        s2 = s5;
_L5:
        if(s1.equals(s2))
            break; /* Loop/switch isn't completed */
        clearResult();
          goto _L3
        SyntaxException syntaxexception;
        syntaxexception;
        mIsError = true;
        mEnterEnd = false;
        errorCursor = 1 + syntaxexception.position;
        if(true) goto _L5; else goto _L4
_L4:
        int j;
        int k;
        int l;
        int i1;
        int j1;
        j = 0;
        k = 0;
        l = s.length();
        i1 = 0;
        j1 = 0;
_L11:
        int k1 = s.length();
        if(j1 >= k1) goto _L7; else goto _L6
_L6:
        char c = s.charAt(j1);
        if(c != '\n' && c != '=') goto _L9; else goto _L8
_L8:
        l = j1;
_L7:
        if(i1 <= 1 && k != 0)
        {
            int l1 = s.length();
            if(k < l1)
                break; /* Loop/switch isn't completed */
        }
        clearResult();
          goto _L3
_L9:
        if((j1 == 0 || j == 40) && (c == '-' || c == '+'))
        {
            j = c;
        } else
        {
            if(Cmyfunc.isOprator(c))
            {
                k = j1;
                i1++;
            }
            j = c;
        }
        j1++;
        if(true) goto _L11; else goto _L10
_L10:
        String s3;
        int i2;
        s3 = s.substring(k, l);
        i2 = s3.length() - 1;
_L14:
label0:
        {
            if(i2 >= 0 && s3.charAt(i2) == ')')
                break label0;
            String s4 = s.substring(k, l);
            if(s4.length() == 0)
            {
                clearResult();
            } else
            {
                replaceInput();
                mDisplay.getText().append(changeColor(s4));
            }
        }
_L3:
        if(true) goto _L13; else goto _L12
_L12:
        l--;
        i2--;
          goto _L14
    }

    public static String sizeTruncate(String s, int i)
    {
        String s2;
        if(i == 100)
        {
            s2 = s;
        } else
        {
            for(int j = 0; j < s.length(); j++)
                if(s.charAt(j) == '.' || s.charAt(j) == '-')
                    i++;

            int k = s.lastIndexOf('E');
            String s1;
            int l;
            int i1;
            if(k != -1)
                s1 = s.substring(k);
            else
                s1 = "";
            l = s1.length();
            i1 = i - l;
            s2 = (new StringBuilder()).append(s.substring(0, Math.min(s.length() - l, i1))).append(s1).toString();
        }
        return s2;
    }

    public void CheckInput()
    {
        int i;
        String s;
        StringBuilder stringbuilder;
        CExpression cexpression;
        i = 0;
        s = getText();
        stringbuilder = getTextBuilder();
        cexpression = new CExpression();
        checkError();
        mPaste = false;
        break MISSING_BLOCK_LABEL_31;
        while(true) 
        {
            do
                return;
            while(s.trim().length() == 0 || stringbuilder.length() == 1 && (stringbuilder.charAt(0) == '-' || stringbuilder.charAt(0) == '(') || stringbuilder.length() == 2 && stringbuilder.equals("\u221A(") || stringbuilder.length() == 3 && (stringbuilder.equals("e^(") || stringbuilder.equals("ln(")) || stringbuilder.length() == 4 && (stringbuilder.equals("sin(") || stringbuilder.equals("cos(") || stringbuilder.equals("tan(")));
            try
            {
                cexpression.checkInputExp(stringbuilder, false);
            }
            catch(SyntaxException syntaxexception)
            {
                mIsError = true;
                mEnterEnd = false;
                i = syntaxexception.message;
                errorCursor = 1 + syntaxexception.position;
            }
            if(errorCursor < 0)
                errorCursor = getText().length();
            if("".equals("***") || "".length() == 0 && 0x7f050015 == i)
                mIsError = false;
            if(mIsError)
                setResult(stringbuilder, "", i);
            mIsError = false;
            mEnterEnd = false;
        }
    }

    public SpannableStringBuilder changeColor(String s)
    {
        return changeColor(new StringBuilder(s));
    }

    public SpannableStringBuilder changeColor(StringBuilder stringbuilder)
    {
        SpannableStringBuilder spannablestringbuilder;
        int i;
        int j;
        spannablestringbuilder = new SpannableStringBuilder(stringbuilder);
        i = 0x3b9ac9ff;
        j = 0;
        if(stringbuilder.length() != 0) goto _L2; else goto _L1
_L1:
        SpannableStringBuilder spannablestringbuilder1 = spannablestringbuilder.append("");
_L8:
        return spannablestringbuilder1;
_L6:
        spannablestringbuilder.setSpan(new ForegroundColorSpan(-13312), j, j + 1, 33);
        i = j;
_L4:
        j++;
_L2:
        if(j >= stringbuilder.length())
            break; /* Loop/switch isn't completed */
        char c = stringbuilder.charAt(j);
        if(!Cmyfunc.isOnlyDigit(c) || c == ',')
            spannablestringbuilder.setSpan(mType, j, j + 1, 33);
        switch(c)
        {
        default:
            if(j > i && Character.isLetter(c))
                spannablestringbuilder.setSpan(new ScaleXSpan(0.85F), j, j + 1, 33);
            if(Cmyfunc.isOpByTwo(c) && c != '^')
            {
                int k;
                if(c == '-' && j > i)
                    k = -13312;
                else
                    k = 0xff81beff;
                spannablestringbuilder.setSpan(new ForegroundColorSpan(k), j, j + 1, 33);
            } else
            {
                char c1;
                if(i > j)
                    c1 = '\uFFFF';
                else
                    c1 = '\uCC00';
                spannablestringbuilder.setSpan(new ForegroundColorSpan(c1), j, j + 1, 33);
            }
            break;

        case 61: // '='
            continue; /* Loop/switch isn't completed */

        case 10: // '\n'
            i = 0x3b9ac9ff;
            spannablestringbuilder.setSpan(new ForegroundColorSpan(-1), j, j + 1, 33);
            break;
        }
        if(true) goto _L4; else goto _L3
        if(true) goto _L6; else goto _L5
_L5:
_L3:
        spannablestringbuilder1 = spannablestringbuilder;
        if(true) goto _L8; else goto _L7
_L7:
    }

    public String changeNumFomat(String s)
    {
        if(s.length() != 0) goto _L2; else goto _L1
_L1:
        String s3 = "";
_L4:
        return s3;
_L2:
        String s1;
        StringBuilder stringbuilder;
        int i;
        String s2;
        NumberFormat numberformat;
        s1 = s.replaceAll(",", "");
        if(s1.contains("NaN"))
        {
            s3 = mContext.getResources().getString(0x7f050001);
            continue; /* Loop/switch isn't completed */
        }
        if(s1.length() == 0)
        {
            s3 = "";
            continue; /* Loop/switch isn't completed */
        }
        stringbuilder = new StringBuilder();
        i = 0;
        if(s1.contains("E"))
        {
            s3 = s1;
            continue; /* Loop/switch isn't completed */
        }
        int j = 0;
label0:
        do
        {
label1:
            {
                if(j <= s1.length())
                {
                    if(j != s1.length() && (s1.charAt(j) == '-' || Cmyfunc.isOnlyDigit(s1.charAt(j))))
                        break label1;
                    i = j;
                }
                int k;
                if(s1.charAt(0) == '-')
                    k = 1;
                else
                    k = 0;
                if(s1.charAt(0) == '-')
                    stringbuilder.append("-");
                s2 = s1.substring(k, i);
                if(!s2.contains("Infinity") && !s2.contains("NaN"))
                    break label0;
                s3 = mContext.getResources().getString(0x7f050001);
                continue; /* Loop/switch isn't completed */
            }
            j++;
        } while(true);
        numberformat = NumberFormat.getNumberInstance(Locale.US);
        numberformat.format(BigDecimal.valueOf(Long.valueOf(s2).longValue()));
        stringbuilder.append(numberformat.format(BigDecimal.valueOf(Long.valueOf(s2).longValue())));
        stringbuilder.append(s1.substring(i));
        s3 = stringbuilder.toString();
        continue; /* Loop/switch isn't completed */
        Exception exception1;
        exception1;
        s3 = mContext.getResources().getString(0x7f050001);
        if(true) goto _L4; else goto _L3
_L3:
    }

    public int checkError()
    {
        int i = 0;
        if(mPaste) goto _L2; else goto _L1
_L1:
        int l = checkCharCount(getTextBuilder(), "=");
        if(l != 0) goto _L4; else goto _L3
_L3:
        int k = -1;
_L6:
        return k;
_L4:
        if(l > 1)
            i = getText().lastIndexOf("=");
        if(i > 0 && getText().charAt(i - 1) == '\n')
            i--;
        int i1 = getText().substring(0, i).lastIndexOf("\n");
        if(i1 != -1 && i1 + 1 <= getTextLength())
            mDisplay.getText().delete(0, i1 + 1);
_L2:
        int j = getText().indexOf("=");
        switch(j)
        {
        default:
            char c = '\0';
            if(j < getTextLength())
                if(getTextLength() == j + 1)
                    c = '\0';
                else
                    c = getText().charAt(j + 1);
            if(!Cmyfunc.isOnlyDigit(c) && c != '-' || c == 0)
            {
                clearResult();
                j = -1;
            }
            // fall through

        case -1: 
            k = j;
            break;
        }
        if(true) goto _L6; else goto _L5
_L5:
    }

    public void clearResult()
    {
        StringBuilder stringbuilder = getTextBuilder();
        int i = stringbuilder.length();
        int j = getText().indexOf("=");
        if(j != -1)
        {
            if(j > 0 && stringbuilder.charAt(j - 1) == '\n')
                j--;
            mDisplay.getText().delete(j, i);
            setFrontText(mDisplay.getText().toString());
        }
    }

    public int commaCount(StringBuilder stringbuilder)
    {
        return checkCharCount(stringbuilder, ",");
    }

    public String evaluate(StringBuilder stringbuilder, boolean flag)
        throws SyntaxException
    {
        CExpression cexpression = new CExpression();
        if(!cexpression.checkInputExp(stringbuilder, flag))
            throw exception.set(0x7f050001, getTextLength());
        String s2;
        try
        {
            s2 = cexpression.evaluateExp();
        }
        catch(SyntaxException syntaxexception1)
        {
            mIsError = true;
            int k;
            String s1;
            int l;
            if(stringbuilder.indexOf("\3670") != -1)
                k = 1 + stringbuilder.indexOf("\3670");
            else
                k = stringbuilder.length() - 1;
            errorCursor = k;
            s1 = syntaxexception1.getMessage();
            l = syntaxexception1.message;
            if(s1 == null)
                s1 = "null";
            if(s1.contains("Division by zero"))
                throw exception.set(0x7f050005, errorCursor);
            if(l == 0x7f050006 || l == 0x7f050007)
                throw exception.set(l, errorCursor);
            else
                throw exception.set(0x7f050001, errorCursor);
        }
        catch(Exception exception1)
        {
            mIsError = true;
            int i;
            String s;
            SyntaxException syntaxexception;
            int j;
            if(stringbuilder.indexOf("\3670") != -1)
                i = 1 + stringbuilder.indexOf("\3670");
            else
                i = stringbuilder.length() - 1;
            errorCursor = i;
            s = exception1.getMessage();
            if(s == null)
                s = "null";
            syntaxexception = exception;
            if(s.contains("Division by zero"))
                j = 0x7f050005;
            else
                j = 0x7f050001;
            throw syntaxexception.set(j, errorCursor);
        }
        return s2;
    }

    public int getCursor(EditText edittext, boolean flag)
    {
        int i = edittext.getSelectionStart();
        int j = edittext.getSelectionEnd();
        int k;
        if(flag)
            k = Math.min(i, j);
        else
            k = Math.max(i, j);
        return k;
    }

    public String getFrontText()
    {
        return frontText;
    }

    public String getText()
    {
        return mDisplay.getText().toString();
    }

    public StringBuilder getTextBuilder()
    {
        clearSB();
        return sb.append(mDisplay.getText());
    }

    public int getTextLength()
    {
        return mDisplay.getText().length();
    }

    public boolean getmCursorState()
    {
        return mCursorState;
    }

    public void goneCursor()
    {
        mDisplay.setCursorVisible(false);
        mHistoryScreen.setCursorVisible(false);
        setmCursorState(false);
    }

    public void insert(StringBuilder stringbuilder)
    {
        char c;
        int i;
        char c1;
        Editable editable;
        int l;
        c = '\0';
        i = 0;
        c1 = stringbuilder.charAt(0);
        mIsError = false;
        int j = getCursor(mDisplay, true);
        int k = getCursor(mDisplay, false);
        if(isSelecting() && k == getTextLength() && j != k)
            mDisplay.getText().delete(j, k);
        else
            mDisplay.setSelection(mDisplay.getText().length());
        if(stringbuilder.length() == 1 && Cmyfunc.isOnlyDigit(stringbuilder.charAt(0)))
            onEnterEnd();
        replaceInput();
        editable = mDisplay.getText();
        l = getCursor(mDisplay, false);
        if(editable.length() != 0 && l != 0 || !stringbuilder.toString().equals("%") && !stringbuilder.toString().equals("!") && !stringbuilder.toString().equals("^(2)") && !stringbuilder.toString().equals("^(")) goto _L2; else goto _L1
_L1:
        return;
_L2:
        if(originCount(getTextBuilder()) + originCount(stringbuilder) <= 100) goto _L4; else goto _L3
_L3:
        setResult(getTextBuilder(), "", 0x7f050008);
          goto _L1
_L4:
        if(Cmyfunc.isOprator(c1) && l == 0 && c1 != '-') goto _L1; else goto _L5
_L5:
        if(l > 0)
            c = editable.charAt(l - 1);
        if(!Cmyfunc.isOprator(c) || !Cmyfunc.isOprator(c1)) goto _L7; else goto _L6
_L6:
        if(!Cmyfunc.isOprator(c)) goto _L9; else goto _L8
_L8:
        int l1;
        if(false)
            l++;
        l1 = l - 1;
_L14:
        if(l1 <= 0) goto _L11; else goto _L10
_L10:
        if(Cmyfunc.isOprator(mDisplay.getText().charAt(l1 - 1))) goto _L13; else goto _L12
_L12:
        i = l1;
_L11:
        boolean flag1 = false;
        if(i > 0 && mDisplay.getText().charAt(i - 1) == '(')
            flag1 = true;
        int i1;
        SpannableStringBuilder spannablestringbuilder6;
        if(flag1 && c1 != '-' && c1 != '+' || i == 0 && c1 != '-')
            spannablestringbuilder6 = changeColor("");
        else
            spannablestringbuilder6 = changeColor(stringbuilder);
        editable.replace(i, l, spannablestringbuilder6);
_L9:
        CheckInput();
        i1 = getCursor(mDisplay, false);
        insertComma(stringbuilder, i1, i1);
        mDisplay.getSelectionEnd();
          goto _L1
_L13:
        l1--;
          goto _L14
_L7:
        boolean flag;
        int j1;
        if(c != '0' || !Cmyfunc.isOnlyDigit(c1))
            break MISSING_BLOCK_LABEL_641;
        flag = false;
        j1 = l - 1;
_L16:
        if(j1 >= 0)
        {
            char c2 = editable.charAt(j1);
            int k1;
            SpannableStringBuilder spannablestringbuilder5;
            if(Cmyfunc.isOnlyDigit(c2) || c2 == '.' || c2 != '\u03C0')
            {
label0:
                {
                    if(c2 != '.' && (!Cmyfunc.isOnlyDigit(c2) || c2 == '0'))
                        break label0;
                    flag = true;
                }
            }
        }
        if(flag)
            break MISSING_BLOCK_LABEL_619;
        if(c1 == 0) goto _L1; else goto _L15
_L15:
        k1 = l - 1;
        spannablestringbuilder5 = changeColor(stringbuilder);
        editable.replace(k1, l, spannablestringbuilder5);
          goto _L9
        j1--;
          goto _L16
        SpannableStringBuilder spannablestringbuilder4 = changeColor(stringbuilder);
        editable.insert(l, spannablestringbuilder4);
          goto _L9
        if((c == ')' || c == 'e' || c == '!' || c == '%' || c == '\u03C0') && Cmyfunc.isOnlyDigit(c1))
        {
            SpannableStringBuilder spannablestringbuilder3 = changeColor((new StringBuilder()).append("\327").append(stringbuilder).toString());
            editable.insert(l, spannablestringbuilder3);
        } else
        if(c == ')' || Cmyfunc.isOnlyDigit(c))
        {
            SpannableStringBuilder spannablestringbuilder;
            if(c1 == 's' || c1 == 'c' || c1 == 't' || c1 == 'l' || c1 == '\u221A' || c1 == 'e' || c1 == '\u03C0')
                spannablestringbuilder = changeColor((new StringBuilder()).append("\327").append(stringbuilder).toString());
            else
                spannablestringbuilder = changeColor(stringbuilder);
            editable.insert(l, spannablestringbuilder);
        } else
        {
            if(c != 'e' && c != '!' && c != '%' && c != '\u03C0')
                continue; /* Loop/switch isn't completed */
            SpannableStringBuilder spannablestringbuilder1;
            if((c1 == 's' || c1 == 'c' || c1 == 't' || c1 == 'l' || c1 == '\u221A' || c1 == 'e' || c1 == '\u03C0') && c != c1 || (c1 == 'e' || c1 == '\u03C0') && c == c1)
                spannablestringbuilder1 = changeColor((new StringBuilder()).append("\327").append(stringbuilder).toString());
            else
                spannablestringbuilder1 = changeColor(stringbuilder);
            editable.insert(l, spannablestringbuilder1);
        }
          goto _L9
        if(c == '(' && (c1 == '\327' || c1 == '\367')) goto _L1; else goto _L17
_L17:
        SpannableStringBuilder spannablestringbuilder2 = changeColor(stringbuilder);
        editable.insert(l, spannablestringbuilder2);
          goto _L9
    }

    public boolean isCheckResult()
    {
        int i = getTextBuilder().indexOf("=");
        boolean flag;
        if(i == -1 || mDisplay.getText().length() - 1 == i)
        {
            flag = false;
        } else
        {
            char c = mDisplay.getText().charAt(i + 1);
            if(Cmyfunc.isOnlyDigit(c) || c == '-')
                flag = true;
            else
                flag = false;
        }
        return flag;
    }

    public boolean isDisplayScreen()
    {
        boolean flag;
        if(mDisplay.getText().length() > 0)
            flag = true;
        else
            flag = false;
        return flag;
    }

    public boolean isHistoryScreen()
    {
        boolean flag;
        if(mHistoryScreen.getText().length() > 0 || mHistory.isHistory())
            flag = true;
        else
            flag = false;
        return flag;
    }

    public boolean isLongClick()
    {
        return isLongClick;
    }

    public boolean isMultiSelection(EditText edittext)
    {
        EditText edittext1;
        boolean flag;
        if(edittext.getId() == 0x7f040004)
            edittext1 = mHistoryScreen;
        else
            edittext1 = mDisplay;
        if(getCursor(edittext1, true) != getCursor(edittext1, false))
            flag = true;
        else
            flag = false;
        return flag;
    }

    public boolean isSelecting()
    {
        return isSelecting;
    }

    public void onAbs()
    {
        replaceInput();
        StringBuilder stringbuilder = getTextBuilder();
        int i = getTextLength();
        StringBuilder stringbuilder1 = new StringBuilder();
        if(i > 0 && (stringbuilder.charAt(i - 1) == ')' || stringbuilder.charAt(i - 1) == 'e' || stringbuilder.charAt(i - 1) == '!' || stringbuilder.charAt(i - 1) == '%' || stringbuilder.charAt(i - 1) == '\u03C0' || Cmyfunc.isOnlyDigit(stringbuilder.charAt(i - 1))))
            stringbuilder1.append("\327");
        stringbuilder1.append("abs(");
        mDisplay.getText().insert(i, changeColor(stringbuilder1));
        int j = getTextLength();
        insertComma(stringbuilder1, j, j);
        CheckInput();
    }

    public void onBackspace()
    {
        String s;
        String s1;
        int i;
        int j;
        int k;
        if(mEnterEnd)
            mEnterEnd = false;
        replaceInput();
        onClearOrigin();
        s = getText();
        s1 = "";
        i = getTextLength();
        j = -1;
        k = 0;
_L3:
        if(k >= checkChar.length)
            break; /* Loop/switch isn't completed */
        j = s.lastIndexOf(checkChar[k]);
          goto _L1
_L5:
        k++;
        if(true) goto _L3; else goto _L2
_L1:
        if(j == -1 || j + checkChar[k].length() != i) goto _L5; else goto _L4
_L4:
        Log.e("onBackspace", (new StringBuilder()).append("check[i] : ").append(checkChar[k]).toString());
        s1 = checkChar[k];
_L2:
        mDisplay.getSelectionStart();
        int l;
        if(!s1.equals(""))
            mDisplay.getText().delete(j, i);
        else
            mDisplay.dispatchKeyEvent(new KeyEvent(0, 67));
        l = mDisplay.getSelectionStart();
        insertComma("", l, l);
        return;
    }

    public void onClear()
    {
        mDisplay.setText("");
        mIsError = false;
        mEnterEnd = false;
        Cmyfunc.clearmOrigin();
    }

    public void onClearOrigin()
    {
        int i = Cmyfunc.getmOrigin().length();
        if(i != 0) goto _L2; else goto _L1
_L1:
        return;
_L2:
        int j = getText().indexOf(Cmyfunc.getmOrigin());
        if(j == -1)
            continue; /* Loop/switch isn't completed */
        if(i + j < getTextLength())
        {
            char c = getText().charAt(i + j);
            if(Cmyfunc.isOpByTwo(c) || c == '!')
                continue; /* Loop/switch isn't completed */
        }
        Cmyfunc.clearmOrigin();
        if(true) goto _L1; else goto _L3
_L3:
    }

    public void onDecimal()
    {
        boolean flag;
        StringBuilder stringbuilder;
        StringBuilder stringbuilder1;
        int i;
        flag = false;
        if(mEnterEnd)
            onClear();
        replaceInput();
        stringbuilder = getTextBuilder();
        stringbuilder1 = new StringBuilder();
        i = getTextLength();
        if(i <= 0 || !Cmyfunc.isChar(stringbuilder.charAt(i - 1))) goto _L2; else goto _L1
_L1:
        return;
_L2:
        if(i == 0)
        {
            mDisplay.getText().insert(i, changeColor("0."));
            insertComma("0.", 0, 0);
            continue; /* Loop/switch isn't completed */
        }
        char c = stringbuilder.charAt(i - 1);
        for(int j = 0; j < i; j++)
        {
            if(stringbuilder.charAt(j) == '.' && flag)
                continue; /* Loop/switch isn't completed */
            if(Cmyfunc.isToken(stringbuilder.charAt(j)))
                flag = false;
            if(stringbuilder.charAt(j) == '.')
                flag = true;
        }

        if(!flag)
        {
            if(c == ')' || c == '!' || c == 'e' || c == '\u03C0')
            {
                stringbuilder1.append("\3270.");
                mDisplay.getText().insert(i, changeColor(stringbuilder1));
                continue; /* Loop/switch isn't completed */
            }
            String s;
            if(Cmyfunc.isOnlyDigit(c))
                s = ".";
            else
                s = "0.";
            stringbuilder1.append(s);
            mDisplay.getText().insert(i, changeColor(stringbuilder1));
        }
        CheckInput();
        insertComma(stringbuilder1, getTextLength(), getTextLength());
        if(true) goto _L1; else goto _L3
_L3:
    }

    public void onEnter()
    {
        onEnter(true);
    }

    public void onEnter(boolean flag)
    {
        String s;
        s = getText();
        onClearOrigin();
        if(s.trim().length() != 0) goto _L2; else goto _L1
_L1:
        return;
_L2:
        int i;
        String s1;
        String s2;
        StringBuilder stringbuilder;
        String s3;
        String s4;
        if(mEnterEnd)
            reCalculation();
        else
            clearResult();
        repairDisplay();
        s1 = "";
        s2 = "";
        i = 0;
        stringbuilder = getTextBuilder();
        s2 = evaluate(stringbuilder, true);
        s1 = doubleToString(Double.parseDouble(s2), 15);
        if(s1.charAt(s1.length() - 1) != '.')
            break MISSING_BLOCK_LABEL_102;
        s4 = s1.substring(0, s1.length() - 1);
        s1 = s4;
_L4:
        setResult(stringbuilder, s1, i);
        if(!mIsError && !s1.contains("Infinity") && !s1.contains("NaN"))
        {
            s3 = changeNumFomat(s1);
            if(flag)
                mHistory.enter(stringbuilder.toString(), s3);
            Cmyfunc.setmTrans(s2);
            Cmyfunc.setmOrigin(s3);
            mEnterEnd = true;
        }
        mIsError = false;
        if(true) goto _L1; else goto _L3
_L3:
        SyntaxException syntaxexception;
        syntaxexception;
        mIsError = true;
        mEnterEnd = false;
        i = syntaxexception.message;
        errorCursor = 1 + syntaxexception.position;
          goto _L4
        Exception exception1;
        exception1;
        mIsError = true;
        mEnterEnd = false;
        i = 0x7f050005;
        exception1.printStackTrace();
          goto _L4
    }

    public void onEnterEnd()
    {
        if(mEnterEnd)
            onClear();
    }

    public void onFraction()
    {
        replaceInput();
        int i = getTextLength();
        String s = getText();
        StringBuilder stringbuilder = new StringBuilder();
        if(i == 0)
        {
            stringbuilder.append("1\367");
            mDisplay.getText().insert(i, changeColor(stringbuilder));
            insertComma(stringbuilder, getTextLength(), getTextLength());
        } else
        {
            if(Cmyfunc.isOnlyDigit(s.charAt(i - 1)) || s.charAt(i - 1) == ')' || s.charAt(i - 1) == 'e' || s.charAt(i - 1) == '!' || s.charAt(i - 1) == '\u03C0')
                stringbuilder.append("\327");
            stringbuilder.append("(1\367");
            mDisplay.getText().insert(i, changeColor(stringbuilder));
            insertComma(stringbuilder, getTextLength(), getTextLength());
        }
    }

    public void onHisClear()
    {
        mHistory.clear();
        mHistoryScreen.setText("");
        onClear();
    }

    public void onParenthesis()
    {
        int i = 0;
        replaceInput();
        String s = getText();
        int j = getTextLength();
        for(int k = 0; k < j; k++)
        {
            if(s.charAt(k) == '(')
                i++;
            if(s.charAt(k) == ')')
                i--;
        }

        StringBuilder stringbuilder = new StringBuilder();
        char c = '\0';
        if(j > 0)
            c = s.charAt(j - 1);
        if(i > 0)
        {
            if(Cmyfunc.isOnlyDigit(c) || c == '!' || c == '%' || c == ')' || c == 'e' || c == '\u03C0' || c == '.')
            {
                stringbuilder.append(")");
            } else
            {
                String s2;
                if(c == ')' && j > 0)
                    s2 = "\327(";
                else
                    s2 = "(";
                stringbuilder.append(s2);
            }
        } else
        {
            String s1;
            if((Character.isDigit(c) || c == 'e' || c == '!' || c == '%' || c == '\u03C0' || c == ',' || c == '.' || c == ')') && j > 0)
                s1 = "\327(";
            else
                s1 = "(";
            stringbuilder.append(s1);
        }
        mDisplay.getText().insert(j, changeColor(stringbuilder));
        CheckInput();
        insertComma(stringbuilder, getTextLength(), getTextLength());
    }

    public void onPlusMinus()
    {
        String s;
        int i;
        int j;
        byte byte0;
        replaceInput();
        s = getText();
        i = getTextLength();
        j = 0;
        byte0 = 0;
        if(i != 0) goto _L2; else goto _L1
_L1:
        mDisplay.getText().insert(0, changeColor("-"));
_L4:
        return;
_L2:
        int k = i;
        do
        {
label0:
            {
                if(k > 0)
                {
                    if(!Cmyfunc.isToken(s.charAt(k - 1)))
                        break label0;
                    j = k - 1;
                }
                int l;
                if(s.charAt(j) == '-')
                {
                    l = j;
                    if(j == 0 && i == 1)
                        byte0 = 3;
                    else
                    if(j > 0 && s.charAt(j - 1) == '(')
                        byte0 = 3;
                    else
                    if(j == 0)
                        byte0 = 3;
                    else
                    if(s.charAt(j - 1) != '(')
                        byte0 = 4;
                } else
                {
                    l = j;
                    if(j == 0 && s.charAt(j) != '(')
                        byte0 = 1;
                    else
                    if(s.charAt(j) == '(')
                        byte0 = 2;
                    else
                    if(s.charAt(j) == ')')
                        byte0 = 5;
                    else
                        byte0 = 4;
                }
                switch(byte0)
                {
                case 1: // '\001'
                    mDisplay.getText().insert(0, changeColor("-"));
                    break;

                case 2: // '\002'
                    mDisplay.getText().insert(l + 1, changeColor("-"));
                    break;

                case 3: // '\003'
                    mDisplay.getText().replace(l, l + 1, "");
                    break;

                case 4: // '\004'
                    mDisplay.getText().insert(l + 1, changeColor("(-"));
                    break;

                case 5: // '\005'
                    mDisplay.getText().insert(l + 1, changeColor("\327(-"));
                    break;
                }
                continue; /* Loop/switch isn't completed */
            }
            if(k == 1 && !Cmyfunc.isToken(s.charAt(k - 1)))
                j = 0;
            k--;
        } while(true);
        if(true) goto _L4; else goto _L3
_L3:
    }

    public void onShift(View view, boolean flag)
    {
        if(flag != isSelecting)
        {
            if(flag)
            {
                view.dispatchKeyEvent(new KeyEvent(0, 59));
            } else
            {
                view.dispatchKeyEvent(new KeyEvent(1, 59));
                view.setSelected(false);
            }
            setSelecting(flag);
        }
    }

    public int originCount(StringBuilder stringbuilder)
    {
        int i;
        if(stringbuilder.toString().length() == 0)
            i = 0;
        else
            i = stringbuilder.toString().length() - commaCount(stringbuilder);
        return i;
    }

    public StringBuilder removeSub(StringBuilder stringbuilder, int i, int j)
    {
        StringBuilder stringbuilder2;
        if(stringbuilder.length() == 0)
        {
            stringbuilder2 = stringbuilder;
        } else
        {
            StringBuilder stringbuilder1 = new StringBuilder();
            for(int k = i; k < j; k++)
                if(stringbuilder.charAt(k) != ',')
                    stringbuilder1.append(stringbuilder.charAt(k));

            stringbuilder2 = stringbuilder1;
        }
        return stringbuilder2;
    }

    public void repairDisplay()
    {
        int i = 0;
        StringBuilder stringbuilder = getTextBuilder();
        for(int j = stringbuilder.length() - 1; j >= 0; j--)
        {
            if(stringbuilder.charAt(j) == ')')
                i--;
            if(stringbuilder.charAt(j) == '(')
                i++;
        }

        if(i != 0)
        {
            int k = 0;
            while(k < i) 
            {
                mDisplay.getText().append(")");
                k++;
            }
        }
    }

    public void replaceInput()
    {
        mEnterEnd = false;
        int i = checkError();
        int j = getCursor(mDisplay, true);
        int k = getCursor(mDisplay, false);
        StringBuilder stringbuilder = new StringBuilder();
        int l;
        if(i != -1)
        {
            stringbuilder.append(getTextBuilder().substring(i + 1).replace("\n", ""));
            mDisplay.setText(changeColor(stringbuilder));
            if(j - i - 1 > 0)
                j = j - i - 1;
            else
                j = 0;
            if(k - i - 1 > 0)
                k = k - i - 1;
            else
                k = 0;
        }
        l = getTextLength();
        if(j > l)
            j = l;
        if(k > l)
            k = l;
        if(j != k && k == l)
            mDisplay.setSelection(j, k);
        else
            mDisplay.setSelection(l);
    }

    public void setFrontText(String s)
    {
        frontText = s;
    }

    public void setLongClick(boolean flag)
    {
        isLongClick = flag;
    }

    public void setResult(StringBuilder stringbuilder, String s, int i)
    {
        String s1;
        int j;
        if(i != 0)
            s1 = mContext.getResources().getString(i);
        else
            s1 = s;
        stringbuilder.length();
        i;
        JVM INSTR lookupswitch 4: default 64
    //                   2131034114: 235
    //                   2131034115: 235
    //                   2131034116: 235
    //                   2131034134: 259;
           goto _L1 _L2 _L2 _L2 _L3
_L1:
        if((i != 0 || s1.contains("Infinity") || s1.contains("NaN")) && (s1.contains("Infinity") || s1.contains("NaN")))
        {
            i = 0x7f050001;
            s1 = mContext.getResources().getString(i);
            errorCursor = mDisplay.getText().length();
        }
        if(i == 0)
            s1 = changeNumFomat(s1);
        j = mDisplay.getText().length();
        mDisplay.getText().insert(j, changeColor((new StringBuilder()).append("\n=").append(s1).toString()));
        setFrontText("");
        mDisplay.setSelection(mDisplay.getText().length());
_L5:
        return;
_L2:
        mDisplay.setText(changeColor(getFrontText()));
        setFrontText("");
        continue; /* Loop/switch isn't completed */
_L3:
        mDisplay.dispatchKeyEvent(new KeyEvent(0, 67));
        setFrontText("");
        if(true) goto _L5; else goto _L4
_L4:
    }

    public void setSelecting(boolean flag)
    {
        isSelecting = flag;
    }

    public void setmCursorState(boolean flag)
    {
        mCursorState = flag;
    }

    public void showCursor()
    {
        mDisplay.setCursorVisible(true);
        mHistoryScreen.setCursorVisible(true);
        setmCursorState(true);
    }

    private String checkChar[];
    public boolean delst;
    public int errorCursor;
    private SyntaxException exception;
    private String frontText;
    public Handler handler;
    private boolean isLongClick;
    private boolean isSelecting;
    private Context mContext;
    private boolean mCursorState;
    private EditText mDisplay;
    public boolean mEnterEnd;
    private History mHistory;
    private EditText mHistoryScreen;
    private boolean mIsError;
    public boolean mPaste;
    private Typeface mType;
    private StringBuilder sb;
}
